
function genGoodsTypesMenu(){
  $.ajax({
		type:"post",
		url: "../custcontroller/goodsTypeCustController/listActiveGoodsTypes",
		dataType: 'json',
		success: function(data, textStatus) {
			debugger;
			if ( data.rows !=null ){
			   for (let i=0;i<data.rows.length;i++){
				  appendGoodsTypeRow(data.rows[i]);
				}
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});

}

function appendGoodsTypeRow(row){
  var rowStr =	"<li><a class=\"list\" href=\"goods_list.html?goodsTypeId="+row.id+"\">"+row.name+"</a></li>\n";
  $("#goodsTypeMenu").append(rowStr);
}

function checkRecommendTypeMenu(recommendType){
  if (recommendType == 2) {
    $("#recommendLabel").text("热销商品");
    $("#newListMenu").removeClass("active");
    $("#hotListMenu").addClass("active");
  } else if (recommendType == 3) {
    $("#recommendLabel").text("新品商品");
    $("#hotListMenu").removeClass("active");
    $("#newListMenu").addClass("active");
  }
}

function parseBoolean(val){
	if (val == undefined|| val == null) return false;
	var isInt = /^(-}+)?\d+$/.test(val);
	if (isInt&& val == "0") return false;
	else if (isInt&& val == "1") return true;
	else if (val.toLowerCase() == "false") return false;
	else if (val.toLowerCase() == "true") return true;
	else if (val.toLowerCase() == "f") return false;
	else if (val.toLowerCase() == "t") return true;
	else if (val.toLowerCase() == "n") return false;
	else if (val.toLowerCase() == "y") return true;
	else if (val.toLowerCase() == "no") return false;
	else if (val.toLowerCase() == "yes") return true;
	else return "";
}

function parseBooleanInt(val){
	var b = parseBoolean(val);
	if (b==undefined||b==null) return 0;
	else if (b==true) return 1;
	else return 0;
}

function parseIntNeg(val){
	if (isBlank(val) || parseInt(val) <= 0) return -1;
	else return parseInt(val);
}

function isBlank(val){
	if (val == undefined|| val == null || val == "" || val== "0" || val == 0) return true;
	else return false;
}

function configPageControls(totalPage,currentPage, recordsCount){
  pageCount = totalPage;
  $("#totalPage").text(totalPage);
  $("#currentPage").text(currentPage);
  $("#current").val(currentPage);
  $("#recordsCount").text(recordsCount);
  $("#first").removeAttr("disabled");
  $("#prev").removeAttr("disabled");
  $("#last").removeAttr("disabled");
  $("#next").removeAttr("disabled");
  if (currentPage <= 1) {
    $("#first").attr("disabled","disabled");
    $("#prev").attr("disabled","disabled");
  }
  if (currentPage >= totalPage) {
    $("#last").attr("disabled","disabled");
    $("#next").attr("disabled","disabled");
  }
}

function next(){
  mypage = mypage + 1;
  if (mypage >= pageCount) mypage = pageCount;
  loadDataGrid(mypage,myrows);
}

function prev(){
  mypage = mypage -1;
  if (mypage <= 1) mypage = 1;
  loadDataGrid(mypage,myrows);
}

function first() {
  mypage = 1;
  loadDataGrid(mypage,myrows);
}

function last() {
  mypage = pageCount;
  loadDataGrid(mypage,myrows);
}

function jump(){
  var mypage = $("#current").val();
  if (mypage <= 1) mypage = 1;
  if (mypage >= pageCount) mypage = pageCount;
  loadDataGrid(mypage,myrows);
}

function decorateMainMenu(page){
  var rowStr = "";
  if (!isLogin()){
    if (page == "register") {
      rowStr += "<li><a href=\"./user_register.html\" class=\"active\">注册</a></li>\n";
    } else {
      rowStr += "<li><a href=\"./user_register.html\">注册</a></li>\n";
    }
    if (page == "login") {
      rowStr += "<li><a href=\"./user_login.html\" class=\"active\">登录</a>\n";
    } else {
      rowStr += "<li><a href=\"./user_login.html\">登录</a>\n";
    }
  } else {
    if (page == "order") {
      rowStr += "<li><a href=\"./order_list.html\" class=\"active\">我的订单</a></li>\n";
    } else {
      rowStr += "<li><a href=\"./order_list.html\">我的订单</a></li>\n";
    }
    if (page == "center") {
      rowStr += "<li><a href=\"./user_center.html\" class=\"active\">个人中心</a></li>\n";
    } else {
      rowStr += "<li><a href=\"./user_center.html\">个人中心</a></li>\n";
    }
    rowStr += "<li><a href=\"javascript:cookieShopFrontLogout()\" >退出</a></li>\n";
    if (isAdmin()){
      rowStr += "<li><a href=\"./admin/index.html\">后台管理</a></li>\n";
    }
  }
  $(".navbar-nav").append(rowStr);
}
